<?php
/**
 * 即时库存
 * Created by PhpStorm.
 * User: echa
 * Date: 2018/1/30
 * Time: 19:23
 *
 */
namespace App\Services\Warehouse;


class JustInTimeInventoryService extends PublicService {

    //即时库存表单ID
    //protected  $Formid='STK_Inventory';

    public function __construct()
    {
        parent::__construct(Config('k3cloud.JustInTimeInventory'));
    }

    /**
     *单据列表查询
     * 1.data：Json格式数据（详情参考Json格式数据）（必录）
    1.1.FormId：业务对象表单Id（必录）
    1.2.FieldKeys：字段keys，字符串类型用逗号分隔，比如"key1,key2..."（必录）
    1.3.FilterString：过滤（非必录）  FNumber=''
    1.4.OrderString：排序字段（非必录）
    1.5.TopRowCount：总行数（非必录）
    1.6.StartRow：开始行（非必录）
    1.7.Limit：最大行数，不能超过2000（非必录）
     */
    public function ExecuteBillQueryJustInTimeInventory($FieldKeys='',$FilterString='',$OrderString='',$TopRowCount=0,$StartRow=0,$Limit=20)
    {

            if (empty($FieldKeys)) {
                $FieldKeys='FMaterialId,FMaterialId.FNumber,FMaterialName,FStockName,FStockLocId,FStockUnitId,FBaseQty,FLockQty,FStockStatusId,FOwnerTypeId,FOwnerId,FOwnerName,FKeeperTypeId,FKeeperName';
            }
           return $this->ExecuteBillQuery($FieldKeys,$FilterString,$OrderString,$TopRowCount,$StartRow,$Limit);
    }

    /**
    *  根据商品编号查询和仓库编号查询即时库存
     *
     */
    public function GetGoodsJustInTimeInventory($goods_sn='',$FStockNumber=''){
        if(empty($goods_sn)){
            return false;
        }
        $FieldKeys='FMaterialId,FMaterialId.FNumber,FMaterialName,FStockId,FStockName,FBaseQty,FStockUnitId.FName,FAVBQty';
        $FilterString="FMaterialId.FNumber='".$goods_sn."'";
        if(!empty($FStockNumber)){
            $FilterString.=" and FStockId.FNumber='".$FStockNumber."'";
        }
        $list=$this->ExecuteBillQuery($FieldKeys,$FilterString);
        if($list){
            return $list;
        }else{
            return false;
        }

    }

}